<template>
	<view>
		<view class="content">
			<uni-title type="h1" :title="info.job.title"></uni-title>
			<view class="red">{{info.job.salary}}/{{info.job.salary_type}}</view>
			<view class="fz08rem mt10">{{info.job.city}}·{{info.job.areas}}　|　{{info.job.education}}　|　{{info.job.experience}}</view>
			<view class="fz08rem mt10"><uni-icons type="location" size="14"></uni-icons>{{info.job.address}}</view>
		</view>
		<view class="view-line"></view>
		<uni-section title="职位描述" type="line" padding>
			<view v-html="info.job.content"></view>
		</uni-section>
		<uni-section title="公司简介" type="line" padding>
			<view v-html="info.company.introduce"></view>
		</uni-section>
		<uni-section title="公司福利" type="line" padding>
			<view v-html="info.company.welfare"></view>
		</uni-section>
		<uni-section padding>
			<uni-list>
				<uni-list-item v-for="item in common.list" :key="item.id" :title="item.publish_user.name" :note="item.content" :thumb="item.publish_user.head_img" thumb-size="lg">
					<template v-slot:footer>
						<view class="text-right"><uni-icons type="hand-up" size="20"></uni-icons>{{item.likes}}</view>
					</template>
				</uni-list-item>
			</uni-list>
		</uni-section>
		<view class="fixed-bottom">
			<uni-goods-nav :fill="true" :options="options" :button-group="customButtonGroup" @click="onClick" @buttonClick="buttonClick" />
		</view>
		
		<uni-popup ref="popup" background-color="#fff" style="width: 0%; margin: 0 auto;">
			<uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="同意" title="投递简历确认" content="投递后不可撤回,确认要投递么?" @confirm="dialogConfirm" @close="dialogClose">
				<view class="p8">
					<uni-title type="h5" title="投递后不可撤回,确认要投递么?"></uni-title>
				</view>
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				options: [{icon: 'star',text: '收藏',}],
				customButtonGroup: [{ icon: 'shop',text: '投递简历', backgroundColor: 'linear-gradient(90deg, #FFD101, #FFD101)', color: '#333' }],
				id:0,
				resume_id:0,
				info:{
					company:{introduce:'--',introduce:'--',welfare:'--'},
					job:{title:'---',salary:0,salary_type:0,city:'--',areas:'--',education:0,experience:0,address:0},
				},
				status:false,
				isCollect:false,
				
				shareinfo:{title:'',img:'',path:''}
				
			}
		},
		onLoad(options){
			this.id = options.id
			this.onGetInfo()
		},
		methods: {
			onGetInfo(){
				let _this = this
				this.$request('/api2/info_'+_this.id,'GET').then(res => {
					_this.info = res.data
					_this.onGetState()
					_this.onGetCollect()
					_this.info.job.education = _this.$func.edu[_this.info.job.education]
					_this.info.job.experience = _this.$func.exp[_this.info.job.experience]
					_this.info.job.salary = _this.info.job.salary_type == 2 ? _this.$func.month_wages[_this.info.job.salary] : _this.$func.year_wages[_this.info.job.salary]
					_this.info.job.salary_type = _this.info.job.salary_type == 2 ? '月' : '年'
					
					_this.shareinfo.title = '招聘:'+_this.info.job.title
					_this.shareinfo.img = _this.info.company.log
				}).catch(err => {
					consol_this.info.job.log(err)
				})
			},
			dialogConfirm(){
				let _this = this
				this.$request('/api2/delivery_resume','POST',{jid:this.id,resume_id:_this.resume_id}).then(res => {
					if(res.code == 0){
						uni.showToast({title: '投递成功',icon: 'success',duration: 2000});
						this.onGetInfo()
						return
					}
					uni.showToast({title: res.data,icon: 'error',duration: 2000});
				}).catch(err => {
					
				})
			},
			onGetState(){
				let _this = this
				this.$request('/api2/delivery_state','POST',{jid:this.id}).then(res => {
					_this.status = res.data
					_this.customButtonGroup[0] = { icon: 'shop',text: '投递简历', backgroundColor: 'linear-gradient(90deg, #FFD101, #FFD101)', color: '#333' }
					if(_this.status){
						_this.customButtonGroup[0] = { icon: 'shop',text: '已投递简历', backgroundColor: 'linear-gradient(90deg, #F5F5F5, #999999)', color: '#333' }
					}
				}).catch(err => {
					
				})
			},
			onGetCollect(){
				let _this = this
				this.$request('/api2/get_collect_state','POST',{jid:this.id}).then(res => {
					_this.isCollect = res.data
					_this.options[0] = {icon: 'star',text: '收藏',}
					if(_this.isCollect){
						_this.options[0] = {icon: 'star-filled',text: '已收藏',}
					}
				}).catch(err => {
					
				})
			},
			onCollect(){
				let _this = this
				this.$request('/api2/collectJob','POST',{jid:this.id}).then(res => {
					if(res.code == 0){
						_this.onGetInfo()
					}
				}).catch(err => {
					
				})
			},
			
			dialogClose(){
				
			},
			onClick(){
				this.onCollect()
			},
			buttonClick(e) {
				if(this.status){
					return false;
				}
				let _this = this
				this.$request('/api/listCV','POST',{}).then(res => {
					if(!res.data.length){
						uni.showToast({title: '请先创建简历',icon: 'error',duration: 2000});return
					}
					_this.resume_id = res.data[0].id
					this.$refs.popup.open('center')
				}).catch(err => {
					
				})
				
			}
		}
	}
</script>

<style scoped lang="scss">
.content{padding: 0px 15px 15px 15px;}
</style>
